<!-- 采购方式 -->
<template>
	<div class="t-wp" v-loading="state.loading">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form class="text-right" :model="state.queryParams" ref="queryForm" :inline="true">
				<el-form-item>
					<el-button type="primary" icon="ele-Plus" @click="showAdd()"> 新增 </el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card class="full-table" shadow="hover" style="margin-top: 8px">
			<el-table :data="state.list" style="width: 100%" border>
				<el-table-column type="index" label="序号" width="55" align="center" />
				<el-table-column prop="name" label="采购方式" show-overflow-tooltip />
				<el-table-column prop="description" label="描述" show-overflow-tooltip />
				<el-table-column label="操作" width="200" align="center" fixed="right" show-overflow-tooltip>
					<template #default="scope">
						<el-button icon="el-icon-edit" size="small" text type="primary" @click="showAdd(scope.row)">编辑</el-button>
						<el-button icon="el-icon-delete" size="small" text type="primary" @click="deleteRow(scope.row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-card>
		<addModal ref="addModalRef" @reload="handleQuery"></addModal>
	</div>
</template>

<script setup name="SupplierManage">
import { onMounted, reactive, ref } from 'vue';
import {useRouter, useRoute} from "vue-router";
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
import addModal from "./modules/addModal.vue";
import {$get, $post, $postparams} from '/@/utils/request';

const router = useRouter();
const route = useRoute();
const addModalRef = ref();

const state = reactive({
	loading: false,

	list: [],
});

onMounted(async () => {
	handleQuery();
});

// 查询操作
const handleQuery = async () => {
	state.loading = true;
	var res = await $post('/projectcfgsrv/getpurchase/0');
	state.list = res.result;
	state.loading = false;
};

// 显示新增
const showAdd = (row) => {
	addModalRef.value.open(row);
}

// 删除项目
const deleteRow = row => {
	ElMessageBox.confirm('此操作将删除该采购方式，是否继续？', '提示', {
		type: 'warning'
	}).then(async () => {
		var res = await $post('/projectcfgsrv/removepurchase/'+row.id);
		ElNotification({
	    title: '提示',
	    message: '删除成功',
	    type: 'success',
	  })
	  // 更新列表
	  handleQuery();
	})
}

</script>

<style lang="scss" scoped>
.t-wp {
	
}
</style>
